define(function(require,exports,module){
	
	
	require.async('/plugins/jquery-validation-1.13.0/jquery.validate',function(){
		require.async('/plugins/jquery-validation-1.13.0/additional-methods',function(){
			$("#realNameVaildate").validate({
				rules:{
					realName:{
			    		required: true,
			    		chnName:true
			    	},
			    	cardId:{
			    		required: true,
			    		isIdCardNo:true
			    	}
			    },
			    messages:{
			    	realName:{
			    		required: "请输入真实姓名",
			    		chnName: "真实姓名仅为中文"
			    	},
			    	cardId:{
			    		required: "请输入二代身份证号码",
			    		isIdCardNo: "身份证格式不对"
			    	}
			   },
				errorElement:"em",
				errorPlacement:function(error,element){
					element.parents("li").find(".msg_tip").html(error);
				},
				success:function(element){
					element.parents("li").find(".msg_tip").html('');
				},
				submitHandler:function(form,event,validator){
					require.async('jquery.form',function(){
						$(form).ajaxSubmit({
							dataType:'json',
							success:function(data){
								require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
									if(data.result){
										$.layer({
											type: 1,
											closeBtn: [0,true],
											title: "&nbsp;",
											area: ['384px', '186px'],
											border: [1, 1, '#cecfd0'],
											time:3,
											page: {
												html: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont okIco">&#xe63d;</i><span>开通托管账户成功</span></div><div class="tipsMsg">3秒后窗口自动关闭</div></div>'
											},
											close: function(index){
												window.location.href = "/member/security/setting.html";
											},
											end: function(){
												window.location.href = "/member/security/setting.html";
											},
											success: function(layero){
												var time =3;
												function closeTime () {
													time--;
													$(".tipsMsg").html(time+"秒后窗口自动关闭");
												}
												setInterval(function(){
													closeTime();
												}, 1000);
											}
										});
									}else{
										$.layer({
											type: 1,
											closeBtn: [0,true],
											title: "&nbsp;",
											area: ['384px', '186px'],
											border: [1, 1, '#cecfd0'],
											page: {
												html: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn failBtn">确定</a></div></div>'
											},
											close: function(index){
												layer.closeAll();
											}
										});
										$(".failBtn").click(function(){
											layer.closeAll();
										});
									}
								})
							}
						});
					})
				}
			});

		})
	});

	require.async('/plugins/jquery-validation-1.13.0/jquery.validate',function(){
		require.async('/plugins/jquery-validation-1.13.0/additional-methods',function() {
			$("#enterpriseCertificationForm").validate({
				rules:{
					companyName:{
						required:true,
						rangelength:[4,50]
					},
					website:{
						required:true,
						url:true
					},
					address:{
						required:true,
						rangelength:[5,50]
					},
					licenseNo:{
						required:true
					},
					licenseAddress:{
						required:true,
						rangelength:[5,50]
					},
					licenseExpireDate:{
						required:true
					},
					businessScope:{
						required:true,
						rangelength:[5,100]
					},
					telephone:{
						required:true,
						fixNumber:true
					},
					email:{
						required:true,
						email:true
					},
					organizationNo:{
						required:true
					},
					summary:{
						required:true,
						rangelength:[5,100]
					},
					legalPerson:{
						required:true,
						rangelength:[2,25],
						chnName:true
					},
					certNo:{
						required:true,
						isIdCardNo:true,
						remote:{
							type: "get",
							url: "/tpp/tppSinaAction/checkCertNo.html",
							data:{
								certNo: function(){
									return $("#certNo").val();
								}
							}
						}
					},
					legalPersonPhone:{
						required:true,
						isMobile:true,
						remote:{
							type: "get",
							url: "/tpp/tppSinaAction/checkLegalPersonPhone.html",
							data:{
								legalPersonPhone: function(){
									return $("#legalPersonPhone").val();
								}
							}
						}
					},
					bankAccountNo:{
						required:true,
						rangelength:[15,19]
					},
					comfirmAccount:{
						required:true,
						equalTo: "#infoyhzh"
					},
					realName:{
						required:true,
						chnName:true
					},
					cardId:{
						required:true,
						isIdCardNo:true,
						remote:{
							type: "get",
							url: "/user/checkCardId.html",
							data:{
								cardId: function(){
									return $("#cardId").val();
								}
							}
						}
					},
					cardPositive:{
						required:true
					},
					cardOpposite:{
						required:true
					},
					file:{
						required:true
					}
				},
				messages:{
					companyName:{
						required:"公司名称不能为空",
						rangelength:"请正确输入公司名称"
					},
					website:{
						required:"企业网址不可为空",
						url: "请输入正确的网址"
					},
					address:{
						required:"企业地址不可为空",
						rangelength:"地址长度必须大于{0}且包含中文"
					},
					licenseNo:{
						required:"执照号不能为空"
					},
					licenseAddress:{
						required:"所在地不可为空",
						rangelength:"地址长度必须大于{0}且包含中文"
					},
					startTime:{
						required:"营业期限不能为空",
					},
					businessScope:{
						required:"营业范围不可为空",
						rangelength:"请填写{0}个字以上"
					},
					telephone:{
						required:"联系电话不可为空",
						fixNumber:"请输入正确的联系电话"
					},
					email:{
						required:"邮箱地址不可为空",
						email:"请输入正确的邮箱地址"
					},
					organizationNo:{
						required:"组织机构不可为空",
					},
					summary:{
						required:"企业简介不可为空",
						rangelength:"描述需在{0}个字级以上"
					},
					legalPerson:{
						required:"企业法人不能为空",
						rangelength:"且输入正确长度的名称",
						chnName:"请输入中文名称"
					},
					certNo:{
						required:"法人身份证号不可为空",
						isIdCardNo:"请输入正确身份证号",
						remote:"该法人证件号码已经存在"
					},
					legalPersonPhone:{
						required:"手机号码不能为空",
						remote:"该法人手机号码已经存在"
					},
					bankAccountNo:{
						required:"请输入银行账号",
						rangelength:"请输入{0}~{1}位银行账号"
					},
					comfirmAccount:{
						required:"确认银行账号",
						equalTo:"两次输入的银行卡不一致，请重新输入"
					},
					file:{
						required:"请上传企业资质文件",
					},
					realName:{
						required:"请输入真实姓名",
						chnName:"真实姓名仅为中文"
					},
					cardId:{
						required:"请输入二代身份证号码",
						isIdCardNo:"请正确输入您的身份证号码",
						remote:"身份证号码已存在"
					}
				},
				errorElement:"em",
				errorPlacement:function(error,element){
					element.parents("li").find(".msg_tip").html(error);
				},
				success:function(element){
					element.parents("li").find(".msg_tip").html('');
				},
				submitHandler:function(form,event,validator){
					require.async('jquery.form',function(){
						require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
							$.layer({
								type: 1,
								closeBtn: [0,true],
								title: "&nbsp;",
								area: ['384px', '186px'],
								border: [1, 1, '#cecfd0'],
								page: {
									html: '<div id="tips"><div class="tipsWrap w384"><div class="tipsTxt"><span>企业开户申请中，请稍等</span></div></div></div>'
								},
								close: function(index){
									window.location.href = "/member/security/setting.html";
								},

							});
						})
						$(form).ajaxSubmit({
							dataType:'json',
							success:function(data){
								require.async(['/plugins/layer-v1.8.4/skin/layer.css','/plugins/layer-v1.8.4/layer.min'],function(){
									if(data.result){
										$("#tips").html('<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont okIco">&#xe63d;</i><span>企业开户申请成功，等待系统审核</span></div><div class="tipsBtnBar"><a href="javascript:;" id="okBtn" class="okBtn">确定</a></div></div>')
										$("#okBtn").click(function(){
											window.location.href = "/member/security/setting.html";
										});
									}else{
										$("#tips").html('<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+data.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" id="okBtn" class="okBtn">确定</a></div></div>')
										$("#okBtn").click(function(){
											window.location.reload();
										});
									}
								})
							}
						});
					})
				}
			})
		})
	})
	//加载城市选择插件
	require.async('jquery-citySelect/jquery.cityselect',function(){
		$("#city").citySelect({
			url:"../../../themes/theme_default/media/js/jquery-citySelect/city.json",
			prov:"浙江", //省份
			city:"杭州", //城市
			dist:"西湖区", //区县
			required:true,
			nodata:"none" //当子集无数据时，隐藏select
		});
	});
	
	$("#file").change(function(){
		var filepath = this.value;
		var relfilename = filepath.replace(/[^\\\/]*[\\\/]+/g,"");
		var filename = relfilename.substring(0,relfilename.lastIndexOf("."));
		document.getElementById('mfileName').value=filename;
	});
});